function HandleDueVisas(gui, user, date, options, message) {
  this._gui = gui;
  this._user = user;
  this._date = date;
  this._options = options;
  this._message = message;
  
  this._search = (this._search) ? this._search : MClientUtils.searchVisa();
  this._page = 1;
  this._order = 't.visa_date_expiry_new';
  this._queue = 'ASC';
  
  this._createElements();
};

HandleDueVisas.prototype._createElements = function() {
  MClientUtils.countIt(new RequestUtils());
  
  DOMUtils.removeChildElements(this._gui.page);
  DOMUtils.removeTableRows(this._gui.result, 1);
  //Preset
  //Object
  //Display
  var _self = this;
  
  if (this._message[0].total > this._message[0].size) {
    new ModulePagination(document, this._gui.page, 500, 50, this._user, this._date, { page: this._message[0].page, total: this._message[0].total, limit: this._message[0].size, callbackFunc: function(page) { _self._page = page; _self._searchData.call(_self, null); }, context: this});
  }
  
  var tr, td, a;
  for (var i = 0, il = this._message[0].data.length; i < il; i++) {
    var tmp = this._message[0].data[i];
    
    tr = this._gui.result.insertRow(-1);
    tr.style.backgroundColor = (tr.rowIndex % 2 == 0) ? '#ececec' : '#fff';
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    a = document.createElement('a');
    a.href = '?t=client&i=' + tmp.client_id;
    a.appendChild(document.createTextNode((tmp.name_first == '' && tmp.name_family == '') ? '-' : tmp.name_first + ' ' + tmp.name_family));
    td.appendChild(a);
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.pass_num == '') ? '-' : tmp.pass_num));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.date_birth == 0 || tmp.date_birth == null) ? '-' : SimpleDate.format(SimpleDate.fromStamp(tmp.date_birth, false), false)));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.phone1 == '') ? '-' : tmp.phone1));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.phone2 == '') ? '-' : tmp.phone2));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.phone3 == '') ? '-' : tmp.phone3));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.client_num == '') ? '-' : tmp.client_num));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.visa_date_expiry_new == 0 || tmp.visa_date_expiry_new == null) ? '-' : SimpleDate.format(SimpleDate.fromStamp(tmp.visa_date_expiry_new, false), false)));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.agent == '') ? '-' : tmp.agent));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((tmp.staff == '') ? '-' : tmp.staff));
    td = tr.insertCell(-1);
    var mail, remv, mail, rmd;
    rmd = document.createElement('input');
    rmd.type = "submit";
    rmd.value = 'Remind Later';
    rmd.style.margin = "0 0 0 5px";
    rmd.style.fontSize = "10px";
    rmd._visa = tmp;
    rmd.onclick = function() { var context = this;
                               var func = function() { new RequestUtils()._custom('visa', JSON.stringify([{ n: 'pz_visa', a: [context._visa], r: [] }]), function(result, params) { location.reload(); }, { pos: DOMUtils.findPos(context) }); };
                               _self._selectDate(this, this._visa.date_reminder, function(sd) { context._visa.date_reminder = SimpleDate.toStamp(sd, false); func(); }, false);
                             };
    edit = document.createElement('img');
    edit.style.padding = "0 5px 0 0";
    edit.style.cursor = 'pointer';
    edit.src = 'image/edit.png';
    edit._visa = tmp;
    edit.onclick = function() { var p = new ModulePopupBox();
                                var div = document.createElement('div');
                                var pos = DOMUtils.findPos(this);
                                p._open(div, { pos: [pos[0] - 600, pos[1] - 500], width: 1000, t: 'Visa' });
                                
                                div.style.verticalAlign = 'top';
                                new ModuleVisaPlus(document, div, null, null, _self._user, _self._date, { object: this._visa, popupBox: p, callbackFunc: function() { location.reload(); } });
                              };
    mail = document.createElement('img');
    mail.style.padding = "0 5px 0 0";
    mail.style.cursor = 'pointer';
    mail.src = 'image/email.png';
    mail._visa = tmp;
    mail.onclick = function() { var p = new ModulePopupBox();
                                var div = document.createElement('div');
                                var pos = DOMUtils.findPos(this);
                                p._open(div, { pos: [pos[0] - 730, pos[1] - 0], width: 730, t: this._visa.name_first + ' ' + this._visa.name_family + ' (' + this._visa.email + ')'});
                                
                                div.style.verticalAlign = 'top';
                                new ModuleEmail(document, div, null, null, _self._user, _self._date, { action: 'remind', table: 'pz_visa', object: this._visa, popupBox: p, callbackFunc: function() { location.reload(); } });
                              };
    remv = document.createElement('img');
    remv.style.padding = "0 0 2px 0";
    remv.style.cursor = 'pointer';
    remv.src = 'image/delete.png';
    remv._visa = tmp;
    remv.onclick = function() { new RequestUtils()._custom('visa', JSON.stringify([{ n: 'pz_visa', a: [], r: [this._visa] }]), function(result, params) { location.reload(); }, { pos: DOMUtils.findPos(this) }); };
    
    td.appendChild(edit);
    td.appendChild(mail);
    td.appendChild(remv);
    td.appendChild(rmd);
  }
  
  if (this._message[0].data.length == 0) {
    tr = this._gui.result.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 11;
    td.style.padding = '10px 0 10px 30px';
    td.style.color = '#ff0000';
    td.style.fontWeight = 'bold';
    td.appendChild(document.createTextNode('No Records Found'));
  }
  //Event
};

HandleDueVisas.prototype._searchData = function(pos) {
  var _self = this;
  new RequestUtils()._custom('visas',
                             JSON.stringify({ s: { due: true }, p: _self._page, o: _self._order, q: _self._queue }),
                             function(result, params) { _self._message[0] = result;
                                                        _self._createElements.call(_self);
                                                      }, { pos: pos });
};

HandleDueVisas.prototype._selectDate = function(display, date, callbackFunc, showTime) {
  var div = document.createElement('div');
  var ds = new DateSelect((date == 0) ? null : SimpleDate.fromStamp(date, false), null, { container: div, showTime: showTime });
  ds._selectFunc = function(sd) { callbackFunc(sd);
                                  if (sd) { 
                                    //display.value = SimpleDate.format(sd, showTime);
                                  } else {
                                    //display.value = '';
                                  }
                                  popupBox._close();
                                };
  
  var popupBox = new ModulePopupBoxSimple();
  var pos = DOMUtils.findPos(display);
  popupBox._open(div, { pos: [pos[0], pos[1] + 85] });
};
